package com.wht.controller.music;

import com.wht.domain.Music;
import com.wht.service.music.AddMusicService;
import com.wht.service.music.UpdateMusicService;
import com.wht.service.music.impl.AddMusicServiceImpl;
import com.wht.service.music.impl.UpdateMusicServiceImpl;
import com.wht.utils.MyBeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author wanghaotian
 * time:2022/11/21,0021 21:17
 * description:
 */

@WebServlet("/UpdateMusicController")
public class UpdateMusicController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Music music = new Music();
        MyBeanUtils.toBean(music, req);
        UpdateMusicService updateMusicService = new UpdateMusicServiceImpl();
        int i = updateMusicService.updateMusic(music);
        if(i>0){
            resp.sendRedirect("/FindAllMusicController");
        }else {
            req.setAttribute("msg", "修改失败");
            req.getRequestDispatcher("/msg.jsp").forward(req, resp);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}